import java.awt.image.BufferedImage;
import java.awt.*;
import java.util.ArrayList;
import java.io.FileInputStream;
import java.io.File;

abstract class Entity
{
	protected double x;
	protected double y;
	protected double angle;
	protected double speed;
	
	protected BufferedImage image;
	protected int xloc[];
	protected int yloc[];
	protected Polygon boundingBox;
	
	protected int maxHealth;
	protected int health;
	protected int armor;
	
	protected boolean die;
	
	public final void setX(double x){this.x = x;}
	public final void setY(double y){this.y = y;}
	public final double getX(){return x;}
	public final double getY(){return y;}
	public final void setAngle(double a){angle = a;}
	public final double getAngle(){return angle;}
	public final double getHealth(){return health;}
	public final int getMaxHealth(){return maxHealth;}
	public final void heal(int h)
	{
		if(h <= 0)
			return;
		
		health += h;
		
		health = Math.min(health,maxHealth);
	}
	public final void setMaxHealth(int h)
	{
		if(h <= 0)
			return;
		maxHealth = h;
	}
	public final void loadImage(String file)
	{
		try
		{
			File f = new File(file);
			
			FileInputStream fis = new FileInputStream(f);
			
			byte b[] = new byte[(int)f.length()];
			
			fis.read(b);
			
			int x;
			for(x = 0; x < b.length; x++)
				if(b[x] == -119 && b[x+1] == 'P' && b[x+2] == 'N' && b[x+3] == 'G')
					break;
			
			int a = 0;
			xloc = new int[x/2+1];
			yloc = new int[x/2+1];
			
			for(int k = 0; k < x; k+=2)
			{
				xloc[a] = b[k];
				yloc[a++] = b[k+1];
			}
			
			xloc[a] = b[0];
			yloc[a] = b[1];
			
			byte imageByte[] = new byte[b.length-x];
			System.arraycopy(b,x,imageByte,0,imageByte.length);
			
			image = ImageToolkit.loadImage(imageByte,true);
		}
		catch(Exception e){}
	}
	public final BufferedImage getImage(){return image;}
	public final Polygon getBoundingBox(){return boundingBox;}
	public final boolean checkCollision(Polygon s)
	{
		if(!s.getBounds().intersects(boundingBox.getBounds()))
			return false;
		
		for(int x = 0; x < s.xpoints.length; x++)
			if(boundingBox.contains(s.xpoints[x],s.ypoints[x]))
				return true;
		
		return false;
	}
	
	public final void mark()
	{
		die = true;
	}
	
	public final boolean isMarked()
	{
		return die;
	}
	
	public abstract void recalculateBoundingBox();
	public abstract void collide(Entity e);
	public abstract void move();
	public abstract void damage(int d);
}